const startYear = 2016

const yearList = []
const now = new Date()
const currentYear = now.getFullYear()
const currentMonth = now.getMonth() + 1
let endYear = currentYear

if (currentMonth === 1) {
  endYear = currentYear - 1
}

for (let i = startYear; i <= endYear; i++) {
  yearList.push(i)
}

function getYearList() {
  return yearList
}

function getMonthList(selectedYear) {
  const monthList = []
  let endMonth

  if (selectedYear && selectedYear < currentYear) {
    endMonth = 12
  } else if (currentMonth === 1) {
    endMonth = 12
  } else {
    endMonth = currentMonth - 1
  }

  for (let i = 0; i < endMonth; i++) {
    monthList.push(i + 1)
  }
  return monthList
}

function getSeasonList(selectedYear) {
  const seasonList = []
  const season = parseInt(currentMonth / 3) + 1
  let endSeason
  if (selectedYear && selectedYear < currentYear) {
    endSeason = 4
  } else if (season === 1) {
    endSeason = 4
  } else {
    endSeason = season - 1
  }

  for (let i = 0; i < endSeason; i++) {
    seasonList.push(i + 1)
  }
  return seasonList
}

function getDefaultYear() {
  return endYear
}

function getDefaultMonth() {
  if (currentMonth === 1) {
    return 12
  } else {
    return currentMonth - 1
  }
}

function getDefaultSeason() {
  const season = parseInt(currentMonth / 3) + 1
  if (season === 1) {
    return 4
  } else {
    return season - 1
  }
}

function getCurrentYear() {
  return currentYear
}

function getCurrentMonth() {
  return currentMonth
}

function getCurrentSeason() {
  return parseInt(currentMonth / 3) + 1
}

function getEvalDefaultYear() {
  const type = getCurrentMonth() <= 6 ? '1' : '2'
  const year = getCurrentYear()
  return type === '1' ? year - 1 : year
  // return getDefaultYear()
}

function getEvalDefaultYearType() {
  const type = getCurrentMonth() <= 6 ? '1' : '2'
  return type === '1' ? '2' : '1'
  // return type
}

export default {
  getYearList,
  getMonthList,
  getSeasonList,
  getDefaultYear,
  getDefaultMonth,
  getDefaultSeason,
  getCurrentYear,
  getCurrentMonth,
  getCurrentSeason,
  getEvalDefaultYear,
  getEvalDefaultYearType
}
